#include<bits/stdc++.h>
using namespace std;


class Solution {
public:
    vector<ListNode*> splitListToParts(ListNode* head, int k) {
        vector<ListNode*> ans;
        ListNode* mov = head, *front, *tail;
        int n = 0;
        while(mov){
            n++;
            mov = mov->next;
        }
        int quotient = n / k, remainder = n % k;//将有 remainder 组 quotient + 1 个节点的和 k - remainder 组 quotient 个节点的。
        mov = head;
        for(int i = 0; i < remainder; i++){
            front = mov, tail = mov;
            for(int j = 0; j < quotient; j++){
                tail = tail->next;
            }
            if(tail){
                mov = tail->next;
                tail->next = nullptr;
            }
            ans.push_back(front);
        }

        for(int i = 0; i < k - remainder; i++){
            front = mov, tail = mov;
            for(int j = 0; j < quotient - 1; j++){
                tail = tail->next;
            }
            if(tail){
                mov = tail->next;
                tail->next = nullptr;
            }
            ans.push_back(front);
        }
        return ans;
    }
};

/**
 * 2021.9.22
 * 注意分析出有多少组多少个节点的即可。
 */